package com.xs.orderservice.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xs
 * date 2018/10/26 11:08
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private LoadBalancerClient loadBalancer;

    @GetMapping("name")
    public String findOrder(){
        ServiceInstance instance = loadBalancer.choose("order-service");
        return "order-xxxxx";
    }


    @GetMapping("serverInfo")
    public String getServerInfo(){
        ServiceInstance instance = loadBalancer.choose("order-service");
        String info = String.format(" serviceId: %s  ,host:  %s,   port: %s",instance.getServiceId(), instance.getHost(), instance.getPort());
        return info;
    }
}
